<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
//require_once 'classes/DataBaseMysql.class.php';

Class BaseWidalReactions {

	protected $m_intId;
	protected $m_intPatientId;
	protected $m_intCasePaperId;
	protected $m_strDescription;
	protected $m_intDoctorId;
	protected $m_intDepartmentId;
	protected $m_intDocumentAttachmentId;
	protected $m_strAttachmentPath;
	protected $connection;

	public function  __construct() {
		if( true == isset( $_SERVER['connection'] ) ) {
			$this->connection = $_SERVER['connection'];
		}
	}

	
	/*******************************************************************************************
	******************************** get Functions *********************************************
	*******************************************************************************************/

	public function getId(){
		return $this->m_intId;
	}

	public function getPatientId(){
		return $this->m_intPatientId;
	}

	public function getCasePaperId(){
		return $this->m_intCasePaperId;
	}

	public function getDescription(){
		return $this->m_strDescription;
	}

	public function getDoctorId(){
		return $this->m_intDoctorId;
	}

	public function getDepartmentId(){
		return $this->m_intDepartmentId;
	}

	public function getDocumentAttachmentId(){
		return $this->m_intDocumentAttachmentId;
	}

	public function getAttachmentPath(){
		return $this->m_strAttachmentPath;
	}
	
	/*******************************************************************************************
	********************************* set Functions ********************************************
	*******************************************************************************************/

	public function setId( $Id ){
		$this->m_intId = $Id;
	}

	public function setPatientId( $PatientId ){
		$this->m_intPatientId = $PatientId;
	}

	public function setCasePaperId( $CasePaperId ){
		$this->m_intCasePaperId = $CasePaperId;
	}

	public function setDescription( $Description ){
		$this->m_strDescription = $Description;
	}

	public function setDoctorId( $DoctorId ){
		$this->m_intDoctorId = $DoctorId;
	}

	public function setDepartmentId( $DepartmentId ){
		$this->m_intDepartmentId = $DepartmentId;
	}

	public function setDocumentAttachmentId( $DocumentAttachmentId ){
		$this->m_intDocumentAttachmentId = $DocumentAttachmentId;
	}

	public function setAttachmentPath( $AttachmentPath ){
		$this->m_strAttachmentPath = $AttachmentPath;
	}
	
	/*******************************************************************************************
	********************************* Insert Functions ********************************************
	*******************************************************************************************/

	public function insert(){
		return $this->connection->RunQuery( "Insert into WIDAL_REACTIONS (patient_id, case_paper_id, description, doctor_id, department_id, document_attachment_id, attachment_path) values (" . $this->getPatientId() . ", " . $this->getCasePaperId() . ", '" . $this->getDescription() . "', " . $this->getDoctorId() . ", " . $this->getDepartmentId() . ", " . $this->getDocumentAttachmentId() . ", '" . $this->getAttachmentPath() . "')");
	}
	
	/*******************************************************************************************
	********************************* Update Functions ********************************************
	*******************************************************************************************/

	public function update(){
		return $this->connection->RunQuery( "UPDATE WIDAL_REACTIONS set  patient_id= " . $this->getPatientId() . ", case_paper_id= " . $this->getCasePaperId() . ", description= '" . $this->getDescription() . "', doctor_id= " . $this->getDoctorId() . ", department_id= " . $this->getDepartmentId() . ", document_attachment_id= " . $this->getDocumentAttachmentId() . ", attachment_path= '" . $this->getAttachmentPath() . "' where id =" . $this->getId() );
	}
	
	/*******************************************************************************************
	********************************* Delete Functions ********************************************
	*******************************************************************************************/

	public function Delete($intId ) {
		$this->connection->RunQuery( "DELETE FROM widal_reactions WHERE id = $intId");
	}

	public function fetchNextId() {
		$result = $this->connection->RunQuery( "SELECT AUTO_INCREMENT as id FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = 'widal_reactions'" );
		if( false == $result ) return NULL;

		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$this->id = $row["id"];
		}

		return $this->id;
	}

}